﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;

namespace Collab.Common
{
    public static class ObservableCollectionEx
    {
        public static void ForEach<T>(this ObservableCollection<T> collection, Action<T> action)
        {
            foreach (var item in collection)
                action.Invoke(item);
        }

        public static T Find<T>(this ObservableCollection<T> collection, Func<T, bool> predicate)
        {
            foreach (var item in collection)
            {
                if (predicate.Invoke(item))
                    return item;
            }
            return default(T);
        }

        public static void AddRange<T>(this ObservableCollection<T> collection, IEnumerable<T> enumerable)
        {
            foreach (var item in enumerable)
                collection.Add(item);
        }
    }
}
